<?php 
class TramitesController extends AppController{
     public $layout = 'default';
    public $name = 'Tramites';
    public $helpers=array('Html','Form');
    public $components=array('Session');
    public $uses = array('Tramite');
   
   
    function index(){
	    
	    $tramites=$this->Tramite->find('all');
	    
	    $this->set(compact('tramites'));
	    
    }
    function insertar($id = null){
        if(!empty($this->data)){
            //debug($this->data);exit;
            $this->Tramite->create();
            if($this->Tramite->save($this->data)){
                $this->Session->setFlash("Tramite ".$this->Tramite->id." guardado");
                $this->redirect(array('action'=>'index'), null, true);
            }else{
                $this->Session->setFlash("No se pudo guardar");
                $this->redirect(array('action'=>'index'), null, true);
            }
        }
    }
    function editar($id=null){
        $this->Tramite->id = $id;
                if (!$id) {
                    $this->Session->setFlash('No existe tal registro');
                    $this->redirect(array('action' => 'index'), null, true);
                }
                if (empty($this->data)) {
                    $this->data = $this->Tramite->read(); 
                } else {
                	
                    if ($this->Tramite->save($this->data)) {
                        $this->Session->setFlash('Los datos fueron modificados');
                        $this->redirect(array('action' => 'index'), null, true);
                    } else {
                        $this->Session->setFlash('no se pudo modificar!!');
                    }
                }
    }
     public function eliminar($id = null){
        if (!$id) {
            $this->Session->setFlash('id Invalida para borrar');
            $this->redirect(array('action' => 'index'));
        }
        if ($this->Tramite->delete($id)) {
           $this->Session->setFlash('El Departamento ' . $id . ' fue borrado');
           $this->redirect(array('action' => 'index'));
        }

    }
}
 ?>